/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.DataRetrieval;

import Utilities.Constants;
import Utilities.Constants.ResourceIdType;
import Utilities.Constants.ResourceRequestType;

/**
 * This is the superclass for all data retrieval requests for local resources. <br><br>
 *
 * Local resources are: servers, users, logs and system data. These resources have
 * only numeric resource IDs.
 *
 * @author Angel Sanadinov
 */
public abstract class LocalResourceRequest extends DataRetrievalRequest
{
    private int resourceId; //the id of the requested resource (for single resource only)

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     *
     * @see Constants#INVALID_NUMERIC_RESOURCE_ID
     */
    public LocalResourceRequest()
    {
        super();
        this.resourceId = Constants.INVALID_NUMERIC_RESOURCE_ID;
    }

    /**
     * Constructs a request for a single resource with the specified resource id.
     *
     * @param requestorId the id of the user that made the request
     * @param resourceId the id of the required resource
     */
    public LocalResourceRequest(int requestorId, int resourceId)
    {
        super(requestorId, Constants.INVALID_SERVER_ID, ResourceRequestType.SINGLE_RESOURCE);
        this.resourceId = resourceId;
    }

    /**
     * Constructs a request for multiple resources.
     *
     * @param requestorId the id of the user that made the request
     */
    public LocalResourceRequest(int requestorId)
    {
        super(requestorId, Constants.INVALID_SERVER_ID, ResourceRequestType.MULTIPLE_RESOURCES);
        this.resourceId = Constants.INVALID_NUMERIC_RESOURCE_ID;
    }

    /**
     * Retrieves the resource id associated with this request.
     *
     * @return the resource id, if available
     */
    public int getResourceId()
    {
        return resourceId;
    }

    /**
     * Sets a resource id that will be associated with this request.
     *
     * @param resourceId the resource id
     */
    public void setResourceId(int resourceId)
    {
        this.resourceId = resourceId;
    }

    /**
     * Checks if the server id associated with the request is valid. <br><br>
     *
     * <b>Note:</b> <i>Always returns true for local resource requests, because
     * there are no servers associated with there resources.</i>
     *
     * @return <code>true</code>
     */
    @Override
    protected boolean isServerIdValid()
    {
        return true;
    }

    /**
     * Retrieves the type of the resource id. <br><br>
     *
     * <b>Note:</b> <i>All local resource have numeric IDs.</i>
     *
     * @return <code>ResourceIdType.NUMERIC_ID</code>
     */
    @Override
    public ResourceIdType getResourceIdType()
    {
        return ResourceIdType.NUMERIC_ID;
    }
}
